using System;
using System.Drawing;
using System.Windows.Forms;
using Conusic;

namespace Imager.LastFmAutocomplete
{
    public sealed partial class AutocompleteItem : UserControl
    {
        public LastFm.Hint Hint { get; private set; }
        private readonly EventHandler onOnSelect;
        private bool keyboardselect;

        public AutocompleteItem(LastFm.Hint hint, EventHandler onOnSelect)
        {
            if (onOnSelect == null) throw new ArgumentNullException("onOnSelect");
            InitializeComponent();
            this.Hint = hint;
            this.onOnSelect = onOnSelect;
            this.label1.Text = hint.ToString();
        }

        private void Label1MouseEnter(object sender, System.EventArgs e)
        {
            this.SetSelect(true);
        }

        private void Label1MouseLeave(object sender, System.EventArgs e)
        {
            this.SetSelect(false);
        }

        public void SetKeyboardSelect()
        {
            keyboardselect = true;
        }

        public void SetSelect(bool selected)
        {
            if (!keyboardselect)
            {
                BackColor = selected ? Color.DarkViolet : Color.White;
            }
        }

        private void AutocompleteItemClick(object sender, System.EventArgs e)
        {
            onOnSelect(this, e);
        }
    }
}
